<?php
/**
 * Created by PhpStorm.
 * User: dt
 * Time: 11:44
 */
namespace backend\utils;
use Yii;
use yii\base\Exception;

/**
 * 图片工具类
 * @package app\utils
 */
class ImageSize
{
    //默认url http
    private static $url_http = 'http://oss.51koudaishu.com/';
    //默认url http
    private static $url_https = 'https://oss.51koudaishu.com/';

    /**
     * 返回根域名
     */
    public static function get_base_url($security=false){
        if($security){
            return self::$url_https;
        }
        return self::$url_http;
    }

    /*
     * 图片处理
     */
    public static function image($data)
    {
        $image = $data['url'];
        if(!$image){
            return '';
        }
        $image = self::$url_http.$image;
        if(!empty($data['security'])){
            $image = self::$url_https.$image;
        }
        if(empty($data['width']) && empty($data['high'])){
            return $image;
        }
        $image .= '?x-oss-process=image/resize,';
        if(!empty($data['width']) && !empty($data['high'])){
            $image .= 'm_fixed,h_'.$data['high'].',w_'.$data['width'];
        }else {
            if (!empty($data['width'])) {
                $image .= 'w_' . $data['width'];
            }
            if (!empty($data['high'])) {
                $image .= 'h_' . $data['high'];
            }
        }
        return $image;
    }


    /*
     * 视频处理
     */
    public static function video($url,$security=false)
    {
        if($security){
            $video = self::$url_https.$url;
        }else{
            $video = self::$url_http.$url;
        }
        return $video;
    }
}
?>